package com.vanke.devops.domain.manager.docker.bean;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;

/**
 * @author 陈景阳
 * @since 2018/6/5
 */
@Getter
@Setter
public class Cpu implements Serializable{
    @JsonProperty("system_cpu_usage")
    private Double systemCpuUsage;
    @JsonProperty("online_cpus")
    private Double onlineCpus;
    @JsonProperty("cpu_usage")
    private CpuUsage cpuUsage;
    @JsonProperty("throttling_data")
    private ThrottlingData throttlingData;

    public double getUsagePercent() {
        return cpuUsage.getTotalUsage() / systemCpuUsage;
    }

    @Getter
    @Setter
    public class CpuUsage{
        @JsonProperty("total_usage")
        private Double totalUsage;
        @JsonProperty("percpu_usage")
        private List<Double> percpuUsage;
        @JsonProperty("usage_in_kernelmode")
        private Double usageInKernelmode;
        @JsonProperty("usage_in_usermode")
        private Double usageInUsermode;
    }

    @Getter
    @Setter
    public class  ThrottlingData{
        private Double periods;
        @JsonProperty("throttled_periods")
        private Double throttledPeriods;
        @JsonProperty("throttled_time")
        private Double throttledTime;
    }
}
